// admin/system/service/sys_oper_log_service.go
package service

import (
	repo "go-admin1/admin/system/dao"
	"go-admin1/admin/system/model"
)

// SysOperLogService 操作日志服务接口
type SysOperLogService interface {
	Create(operLog *model.SysOperLog) error
	GetByID(id int64) (*model.SysOperLog, error)
	Delete(id int64) error
	List(page, pageSize int) ([]*model.SysOperLog, int64, error)
	CleanAll() error
}

type sysOperLogService struct {
	operLogDao repo.SysOperLogDao
}

func (s sysOperLogService) Create(operLog *model.SysOperLog) error {
	return s.operLogDao.Create(operLog)
}

func (s sysOperLogService) GetByID(id int64) (*model.SysOperLog, error) {
	operLog, err := s.operLogDao.GetByID(id)
	if err != nil {
		return nil, err
	}
	return operLog, nil
}

func (s sysOperLogService) Delete(id int64) error {
	return s.operLogDao.Delete(id)
}

func (s sysOperLogService) List(page, pageSize int) ([]*model.SysOperLog, int64, error) {
	operLogs, total, err := s.operLogDao.List(page, pageSize)
	if err != nil {
		return nil, 0, err
	}
	return operLogs, total, nil
}

func (s sysOperLogService) CleanAll() error {
	return s.operLogDao.CleanAll()
}

// NewSysOperLogService 创建操作日志服务实例
func NewSysOperLogService() SysOperLogService {
	return &sysOperLogService{
		operLogDao: repo.NewSysOperLogDao(),
	}
}
